home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October : Technology Seed / ATS Oct. '97.toast / Navigation Services SDK 1.0a6 / Examples / Sampler / Sampler ƒ / document.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-31  |  17.0 KB  |  673 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        document.c
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment DocSeg
  9.  
  10. #ifndef __DRAG__
  11. #include <Drag.h>
  12. #endif
  13.  
  14. #ifndef __TOOLUTILS__
  15. #include <ToolUtils.h>
  16. #endif
  17.  
  18.  
  19. #ifndef Common_Defs
  20. #include "Common.h"
  21. #endif
  22.  
  23. #ifndef __MYSPRINTF__
  24. #include "Mysprintf.h"
  25. #endif
  26.  
  27. #ifndef __NAVIGATION__
  28. #include "Navigation.h"
  29. #endif
  30.  
  31. const             printID = -8192;    // string rsrc ID if print driver name
  32. const OSType    strType = 'STR ';    // string resource type
  33.  
  34. extern short         gDocumentCount;
  35. extern Document*    gDocumentList[kMaxDocumentCount];
  36. extern short         gQuitting;
  37. extern short        gCanUndoDrag;
  38. extern WindowPtr    gUndoFrontmost, gLastFrontmost;
  39. extern Boolean        gCanDrag;
  40.  
  41. extern pascal OSErr MyTrackingHandler(short message, WindowPtr theWindow, void* handlerRefCon, DragReference theDrag);
  42. extern pascal OSErr MyReceiveDropHandler(WindowPtr theWindow, unsigned long handlerRefCon, DragReference theDrag);
  43.  
  44. void PositionDocumentParts(Document* theDocument);
  45. void DoDrawGrowIcon(WindowPtr theWindow);
  46.  
  47. DragReceiveHandlerUPP     receiveHandler;
  48. DragTrackingHandlerUPP     trackingHandler;
  49. DragSendDataUPP         sendHandler;
  50.  
  51. pascal void myventProc(const     NavEventCallbackMessage callBackSelctor, 
  52.                                                 NavCBRecPtr callBackParms, 
  53.                                                 NavCallBackUserData callBackUD);
  54. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting);
  55.  
  56.  
  57. // **********************************************************************
  58. // *
  59. // *    AddText()
  60. // *
  61. // **********************************************************************
  62. void AddText(Document* theDocument, Ptr text, long len)
  63. {
  64.     if (theDocument->theTE != NULL)
  65.         {
  66.         TEInsert(text,len,theDocument->theTE);
  67.         theDocument->dirty = true;
  68.         TESelView(theDocument->theTE);
  69.         AdjustScrollBar((Document*)GetWRefCon(theDocument->theWindow));
  70.         }
  71. }
  72.  
  73.  
  74. // **********************************************************************
  75. // *
  76. // *    AdjustDocumentView()
  77. // *
  78. // **********************************************************************
  79. void AdjustDocumentView(Document* theDocument)
  80. {    
  81.     short    delta, docTop, docTopLimit;
  82.  
  83.     delta = (theDocument->vScrollPos - GetControlValue(theDocument->vScroll)) * ScrollResolution;
  84.  
  85.     if (delta && theDocument->theTE)
  86.         {
  87.         if (delta > 0)
  88.             {
  89.             docTop = (**(theDocument->theTE)).destRect.top;
  90.             docTopLimit = (**(theDocument->theTE)).viewRect.top + TopMargin;
  91.             if (docTop + delta > docTopLimit)
  92.                 delta = docTopLimit - docTop;
  93.             }
  94.         TEScroll(0,delta,theDocument->theTE);
  95.         theDocument->vScrollPos = GetControlValue(theDocument->vScroll);
  96.         }
  97. }
  98.  
  99.  
  100. // **********************************************************************
  101. // *
  102. // *    AdjustScrollBar()
  103. // *
  104. // **********************************************************************
  105. void AdjustScrollBar(Document* theDocument)
  106. {    
  107.     short        docTop, docBottom, viewTop, viewBottom;
  108.     short        offTop, offBottom;
  109.     RgnHandle    viewRgn;
  110.  
  111.     if (theDocument->theTE != NULL)
  112.         {
  113.         docTop = (**(theDocument->theTE)).destRect.top;
  114.         docBottom = docTop + TEGetHeight(32767,0,theDocument->theTE);
  115.         viewTop = (**(theDocument->theTE)).viewRect.top;
  116.         viewBottom = (**(theDocument->theTE)).viewRect.bottom;
  117.     
  118.         offTop = ((viewTop - (docTop - TopMargin)) + ScrollResolution - 1) / ScrollResolution;
  119.         offBottom = (((docBottom + BottomMargin) - viewBottom) + ScrollResolution - 1) / ScrollResolution;
  120.         if (offTop < 0)
  121.             offTop = 0;
  122.         if (offBottom < 0)
  123.             offBottom = 0;
  124.     
  125.         theDocument->vScrollPos = offTop;
  126.     
  127.         SetControlMaximum(theDocument->vScroll,offTop + offBottom);
  128.         SetControlValue(theDocument->vScroll,offTop);
  129.     
  130.         viewRgn = NewRgn();
  131.         RectRgn(viewRgn,&(**(theDocument->theTE)).viewRect);
  132.         SectRgn(viewRgn,theDocument->hiliteRgn,theDocument->hiliteRgn);
  133.         DisposeRgn(viewRgn);
  134.         }
  135. }
  136.  
  137.  
  138. // **********************************************************************
  139. // *
  140. // *    PositionDocumentParts()
  141. // *
  142. // **********************************************************************
  143. void PositionDocumentParts(Document* theDocument)
  144. {    
  145.     Rect globalBounds = theDocument->theWindow->portRect;
  146.     Rect theRect;
  147.  
  148.     // size the vertical scrollbar:
  149.     SizeControl(theDocument->vScroll,kScrollBarWidth,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+4);
  150.     MoveControl(theDocument->vScroll,globalBounds.right+2 - kScrollBarPos,-1);
  151.  
  152.     // size the horizontal scrollbar:
  153.     SizeControl(theDocument->hScroll,(globalBounds.right - globalBounds.left - kScrollBarPos)+4,kScrollBarWidth);
  154.     MoveControl(theDocument->hScroll,-1,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+2);
  155.  
  156.     theRect = globalBounds;
  157.     theRect.right  -= 15;
  158.     theRect.bottom -= 15;
  159.     (**(theDocument->theTE)).viewRect = theRect;
  160.     (**(theDocument->theTE)).destRect.right = theRect.right - RightMargin;
  161.     TECalText(theDocument->theTE);
  162. }
  163.  
  164.  
  165. void SizeDocWindow(Document* theDocument)
  166. {
  167.     short length = 0;
  168.     short width = 0;
  169.     if (theDocument->fPict != NULL)
  170.         {
  171.         if ((**((PicHandle)theDocument->fPict)).picFrame.right >= qd.screenBits.bounds.right)
  172.             width = qd.screenBits.bounds.right-40;
  173.         else
  174.             width = (**((PicHandle)theDocument->fPict)).picFrame.right;
  175.  
  176.         if ((**((PicHandle)theDocument->fPict)).picFrame.bottom >= qd.screenBits.bounds.bottom)
  177.             length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;
  178.         else
  179.             length = (**((PicHandle)theDocument->fPict)).picFrame.bottom;
  180.         }
  181.     else
  182.         {
  183.         length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;    
  184.         width = kWindowWidth;
  185.         }
  186.     SizeWindow(theDocument->theWindow,width,length,true);
  187. }
  188.  
  189.  
  190. // **********************************************************************
  191. // *
  192. // *    NewDocument()
  193. // *
  194. // **********************************************************************
  195. Document* NewDocument(Boolean newDocAsPICT)
  196. {    
  197.     OSErr            theErr = noErr;
  198.     Document*        theDocument;
  199.     WindowPtr        theWindow;
  200.     Rect            theRect = {0,0,16,16};
  201.     TextStyle        theStyle;
  202.     TEStyleHandle    theStyleHandle;
  203.     Point            thePoint;
  204.     Rect            theSize;
  205.     short            length = 0, width = 0;
  206.     Str255            windTitle;
  207.     short            offset;
  208.     Rect            bounds;
  209.  
  210.     if (gDocumentCount == kMaxDocumentCount)
  211.         return ((Document*)0L);
  212.         
  213.     theDocument = gDocumentList[gDocumentCount++] = (Document*)NewPtr(sizeof(Document));
  214.     
  215.     // create the window
  216.     offset = gDocumentCount-1;
  217.     theDocument->theWindow = theWindow = NewCWindow(0L,&theSize,(unsigned char*)"\p",false,zoomDocProc,(WindowPtr)-1L,true,0L);
  218.     MoveWindow(theDocument->theWindow,(10+(offset*20)),(27+(offset*20)+LMGetMBarHeight()),true);
  219.     
  220.     bounds = theWindow->portRect;
  221.  
  222.     // setup the window title
  223.     Mysprintf((StringPtr)windTitle,(StringPtr)"untitled %d",gDocumentCount);
  224.     MyC2PStr((char*)windTitle);
  225.     SetWTitle(theDocument->theWindow,windTitle);
  226.     
  227.     SetWRefCon(theWindow,(long)theDocument);
  228.  
  229.     SetPort(theWindow);
  230.     thePoint.v = bounds.top;
  231.     thePoint.h = bounds.left;
  232.  
  233.     LocalToGlobal(&thePoint);
  234.     if (thePoint.h < 10)
  235.         MoveWindow(theWindow,InitialH,InitialV,false);
  236.  
  237.     if (newDocAsPICT)
  238.         {
  239.         theDocument->theTE = NULL;
  240.         theDocument->fPict = NULL;
  241.         theDocument->fPictLength = 0;
  242.         theDocument->fHeader = NULL;
  243.         }
  244.     else
  245.         {
  246.         theDocument->fPict = NULL;
  247.  
  248.         SizeDocWindow(theDocument);
  249.  
  250.         theDocument->vScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  251.         theDocument->hScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  252.  
  253.         theDocument->theTE = TEStyleNew(&theRect,&theRect);
  254.         (**(theDocument->theTE)).destRect.top    = TopMargin;
  255.         (**(theDocument->theTE)).destRect.left   = LeftMargin;
  256.         (**(theDocument->theTE)).destRect.bottom = 32767;
  257.         
  258.         TEAutoView(true,theDocument->theTE);
  259.  
  260.         TEFeatureFlag(teFOutlineHilite,teBitSet,theDocument->theTE);
  261.  
  262.         theDocument->hiliteRgn = NewRgn();
  263.         theStyleHandle = TEGetStyleHandle(theDocument->theTE);
  264.         (**theStyleHandle).teRefCon = (long)theDocument;
  265.  
  266.         theStyle.tsFont = 21;
  267.         theStyle.tsSize = 12;
  268.         TESetStyle(doFont + doSize,&theStyle,false,theDocument->theTE);
  269.         
  270.         theDocument->vScrollPos = 0;
  271.         theDocument->undoDragText = 0L;
  272.         
  273.         PositionDocumentParts(theDocument);
  274.  
  275.         if (gCanDrag && theDocument->theTE != NULL)
  276.             {
  277.             receiveHandler = NewDragReceiveHandlerProc(&MyReceiveDropHandler);
  278.             trackingHandler = NewDragTrackingHandlerProc(&MyTrackingHandler);
  279.             
  280.             theErr = InstallReceiveHandler(receiveHandler,theWindow,(void*)theDocument);
  281.             theErr = InstallTrackingHandler(trackingHandler,theWindow,(void*)theDocument);
  282.             }
  283.         }
  284.     
  285.     theDocument->fRefNum = 0;
  286.     theDocument->dirty = false;
  287.     
  288.     return theDocument;
  289. }
  290.  
  291.  
  292. // **********************************************************************
  293. // *
  294. // *    OpenAskSaveChanges()
  295. // *
  296. // **********************************************************************
  297. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting)
  298. {
  299.     OSStatus                theStatusErr     = noErr;
  300.     OSErr                     theErr             = noErr;
  301.     NavAskSaveChangesResult    reply             = 0;
  302.     NavAskSaveChangesAction    action             = 0;
  303.     Str255                    appName;
  304.     NavEventUPP                eventUPP = NewNavEventProc(myEventProc);
  305.     
  306.     if (quitting)
  307.         action = kNavSaveChangesQuittingApplication;
  308.     else
  309.         action = kNavSaveChangesClosingDocument;
  310.         
  311.     GetIndString((unsigned char*)&appName,rAppStringsID,sApplicationName);
  312.     
  313.     theErr = NavAskSaveChanges(    appName,
  314.                                 docName,
  315.                                 action,
  316.                                 &reply,
  317.                                 eventUPP,
  318.                                 (NavCallBackUserData)&gDocumentList);
  319.     
  320.     DisposeRoutineDescriptor(eventUPP);
  321.  
  322.     return reply;
  323. }
  324.  
  325.  
  326. // **********************************************************************
  327. // *
  328. // *    CloseDocument()
  329. // *
  330. // **********************************************************************
  331. void CloseDocument(Document* theDocument, Boolean quitting)
  332. {    
  333.     OSErr    theErr = noErr;
  334.     short    index;
  335.     Str255    theName;
  336.  
  337.     index = 0;
  338.     while ((gDocumentList[index] != theDocument) && (index < kMaxDocumentCount))
  339.         index++;
  340.  
  341.     if (gDocumentList[index] == theDocument)
  342.         {
  343.         if (theDocument->dirty)
  344.             {
  345.             NavAskSaveChangesResult result = 0;
  346.  
  347.             GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  348.             result = OpenAskSaveChanges(theName,quitting);
  349.             switch (result)
  350.                 {
  351.                 case askSaveChangesSave:
  352.                     if (!DoSaveDocument(theDocument))
  353.                         {
  354.                         gQuitting = false;    // don't quit yet!
  355.                         //return;
  356.                         }
  357.                     break;
  358.                 case askSaveChangesCancel:
  359.                     gQuitting = false;    // don't quit yet!
  360.                     //return;
  361.                     break;
  362.                 }
  363.             if (result == askSaveChangesCancel)
  364.                 return;    // don't close the document
  365.             }
  366.  
  367.         if (theDocument->fRefNum)
  368.             FSClose(theDocument->fRefNum);
  369.  
  370.         if (gCanDrag && theDocument->theTE != NULL)
  371.             {
  372.             theErr = RemoveReceiveHandler(receiveHandler,theDocument->theWindow);
  373.             theErr = RemoveTrackingHandler(trackingHandler,theDocument->theWindow);
  374.             }
  375.         
  376.         if (theDocument->theTE != NULL)
  377.             {
  378.             DisposeRgn(theDocument->hiliteRgn);
  379.             TEDispose(theDocument->theTE);
  380.             
  381.             if (theDocument->undoDragText)
  382.                 {
  383.                 DisposeHandle(theDocument->undoDragText);
  384.                 theDocument->undoDragText = 0L;
  385.                 }
  386.             }
  387.         else
  388.             {
  389.             if (theDocument->fPict != NULL)
  390.                 KillPicture((PicHandle)theDocument->fPict);    
  391.             if (theDocument->fHeader != NULL)
  392.                 DisposeHandle(theDocument->fHeader);
  393.             }
  394.  
  395.         DisposeWindow(theDocument->theWindow);
  396.  
  397.         while (index < kMaxDocumentCount)
  398.             {
  399.             gDocumentList[index] = gDocumentList[index + 1];
  400.             index++;
  401.             }
  402.  
  403.         DisposePtr((Ptr)theDocument);
  404.         gDocumentCount--;
  405.     }
  406. }
  407.  
  408.  
  409. // **********************************************************************
  410. // *
  411. // *    DoActivateDocument()
  412. // *
  413. // **********************************************************************
  414. void DoActivateDocument(Document* theDocument, short activate)
  415. {    
  416.     if (theDocument->theTE != NULL)
  417.         {
  418.         if (activate)
  419.             {
  420.             TEActivate(theDocument->theTE);
  421.             HiliteControl(theDocument->vScroll,0);
  422.             HiliteControl(theDocument->hScroll,0);
  423.             DoDrawGrowIcon(theDocument->theWindow);
  424.             TEGetHiliteRgn(theDocument->hiliteRgn,theDocument->theTE);
  425.             }
  426.         else
  427.             {
  428.             TEDeactivate(theDocument->theTE);
  429.             HiliteControl(theDocument->vScroll,255);
  430.             HiliteControl(theDocument->hScroll,255);
  431.             DoDrawGrowIcon(theDocument->theWindow);
  432.             }
  433.         }
  434. }
  435.  
  436.  
  437. // **********************************************************************
  438. // *
  439. // *    IsDocumentWindow()
  440. // *
  441. // **********************************************************************
  442. Document* IsDocumentWindow(WindowPtr theWindow)
  443. {    
  444.     short        index = 0;
  445.     Document*    theDocument;
  446.  
  447.     theDocument = (Document*)GetWRefCon(theWindow);
  448.  
  449.     while ((gDocumentList[index] != theDocument) && (index < gDocumentCount))
  450.         index++;
  451.  
  452.     if (gDocumentList[index] == theDocument)
  453.         return(theDocument);
  454.     else
  455.         return((Document*)0L);
  456. }
  457.  
  458.  
  459. // **********************************************************************
  460. // *
  461. // *    DoSelectAllDocument()
  462. // *
  463. // **********************************************************************
  464. void DoSelectAllDocument(Document* theDocument)
  465. {
  466.     if (theDocument && (theDocument->theTE))
  467.         TESetSelect(0,32767,theDocument->theTE);
  468. }
  469.  
  470.  
  471. // **********************************************************************
  472. // *
  473. // *    DisableUndoDrag()
  474. // *
  475. // **********************************************************************
  476. void DisableUndoDrag()
  477. {    
  478.     short        index;
  479.     Document*    theDoc;
  480.  
  481.     gCanUndoDrag = slCantUndo;
  482.  
  483.     index = gDocumentCount;
  484.     while (index--)
  485.         {
  486.         theDoc = gDocumentList[index];
  487.         if (theDoc->undoDragText)
  488.             {
  489.             DisposeHandle(theDoc->undoDragText);
  490.             theDoc->undoDragText = 0L;
  491.             }
  492.         }
  493. }
  494.  
  495.  
  496. // **********************************************************************
  497. // *
  498. // *    DoUndoDrag()
  499. // *
  500. // **********************************************************************
  501. void DoUndoDrag()
  502. {    
  503.     short        index, selStart, selEnd;
  504.     Document*    theDoc;
  505.     Handle        theText;
  506.     WindowPtr    theWindow;
  507.     Rect        theRect;
  508.  
  509.     if (gCanUndoDrag != slCantUndo)
  510.         {
  511.         theWindow = 0L;
  512.         index = gDocumentCount;
  513.         while (index--)
  514.             {
  515.             theDoc = gDocumentList[index];
  516.  
  517.             SetPort(theDoc->theWindow);
  518.             
  519.             if (theText = theDoc->undoDragText)
  520.                 {
  521.                 Rect        bounds = theDoc->theWindow->portRect;
  522.  
  523.                 theDoc->undoDragText = (**theDoc->theTE).hText;
  524.                 (**theDoc->theTE).hText = theText;
  525.  
  526.                 TECalText(theDoc->theTE);
  527.  
  528.                 selStart = theDoc->undoSelStart;
  529.                 selEnd   = theDoc->undoSelEnd;
  530.                 TESetSelect(selStart,selEnd,theDoc->theTE);
  531.                 theDoc->undoSelStart = theDoc->lastSelStart;
  532.                 theDoc->undoSelEnd   = theDoc->lastSelEnd;
  533.                 theDoc->lastSelStart = selStart;
  534.                 theDoc->lastSelEnd   = selEnd;
  535.  
  536.                 theRect = bounds;
  537.                 theRect.right  -= 15;
  538.                 theRect.bottom -= 15;
  539.                 EraseRect(&theRect);
  540.                 TEUpdate(&theRect,theDoc->theTE);
  541.                 }
  542.             }
  543.  
  544.         if (gCanUndoDrag == slUndoDrag)
  545.             gCanUndoDrag = slRedoDrag;
  546.         else
  547.             gCanUndoDrag = slUndoDrag;
  548.  
  549.         theWindow = gUndoFrontmost;
  550.         gUndoFrontmost = gLastFrontmost;
  551.         gLastFrontmost = theWindow;
  552.         }
  553. }
  554.  
  555.  
  556. // *****************************************************************************
  557. // *
  558. // *    DoDrawGrowIcon()
  559. // *
  560. // *****************************************************************************
  561. void DoDrawGrowIcon(WindowPtr theWindow)
  562. {
  563.     RgnHandle saveClipRgn = NewRgn();
  564.     Rect tempRect;
  565.  
  566.     if (saveClipRgn)
  567.         {
  568.         GetClip(saveClipRgn);
  569.     
  570.         SetRect(&tempRect,
  571.                 theWindow->portRect.right-15,
  572.                 theWindow->portRect.bottom-15,
  573.                 theWindow->portRect.right,
  574.                 theWindow->portRect.bottom);
  575.         ClipRect(&tempRect);
  576.         DrawGrowIcon(theWindow);
  577.         
  578.         SetClip(saveClipRgn);
  579.         DisposeRgn(saveClipRgn);
  580.         }
  581.     else
  582.         DrawGrowIcon(theWindow);
  583. }
  584.  
  585.  
  586. // *****************************************************************************
  587. // *
  588. // *    UpdateWindow()
  589. // *
  590. // *    Update event is received for a document window.
  591. // *
  592. // *****************************************************************************
  593. void UpdateWindow(Document* theDocument)
  594. {    
  595.     WindowPtr     theWindow = theDocument->theWindow;
  596.     Rect        bounds = theDocument->theWindow->portRect;
  597.     
  598.     SetPort(theWindow);
  599.     
  600.     BeginUpdate(theWindow);
  601.  
  602.     EraseRect(&bounds);
  603.     if (theDocument->theTE != NULL)
  604.         {
  605.         DrawControls(theWindow);
  606.         DoDrawGrowIcon(theWindow);
  607.         if (theDocument->theTE)
  608.             TEUpdate(&bounds,theDocument->theTE);
  609.         }
  610.     else
  611.         {
  612.         if (theDocument->fPict != NULL)
  613.             DrawPicture((PicHandle)theDocument->fPict,&((**((PicHandle)theDocument->fPict)).picFrame));
  614.         }
  615.     EndUpdate(theWindow);
  616. }
  617.  
  618.  
  619. // *****************************************************************************
  620. // *
  621. // *    DoZoomDocument()
  622. // *
  623. // *****************************************************************************
  624. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart)
  625. {
  626.     GrafPtr    oldPort;
  627.     GetPort(&oldPort);
  628.     
  629.     SetPort(theWindow);
  630.     EraseRect(&theWindow->portRect);
  631.     ZoomWindow(theWindow,thePart,theWindow == FrontWindow());
  632.     
  633.     if (theDocument->theTE != NULL)
  634.         {
  635.         PositionDocumentParts((Document*)GetWRefCon(theWindow));
  636.         AdjustScrollBar((Document*)GetWRefCon(theWindow));
  637.         DoDrawGrowIcon(theWindow);
  638.         }
  639.  
  640.     InvalRect(&theWindow->portRect);
  641.  
  642.     SetPort(oldPort);
  643. }
  644.  
  645.  
  646. // *****************************************************************************
  647. // *
  648. // *    GrowDocumentWindow()
  649. // *
  650. // *****************************************************************************
  651. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint)
  652. {    
  653.     long    result;
  654.     Rect    sizeRect;
  655.     Rect    bounds = theWindow->portRect;
  656.  
  657.     SetPort(theWindow);
  658.     
  659.     sizeRect = qd.screenBits.bounds;
  660.     if (!(result = GrowWindow(theWindow,thePoint,&sizeRect)))
  661.         return;
  662.         
  663.     SizeWindow(theWindow,LoWord(result),HiWord(result),false);
  664.  
  665.     PositionDocumentParts((Document*)GetWRefCon(theWindow));
  666.  
  667.     AdjustScrollBar((Document*)GetWRefCon(theWindow));
  668.  
  669.     DoDrawGrowIcon(theWindow);
  670.  
  671.     bounds = theWindow->portRect;
  672.     InvalRect(&bounds);
  673. }